package cn.ibobo.lease.app.service.impl;

import cn.ibobo.lease.app.dao.LeaseResDetailMapper;
import cn.ibobo.lease.app.dao.ResLeaseMapper;
import cn.ibobo.lease.app.service.LeaseResDetailService;
import cn.ibobo.lease.common.base.BaseMapper;
import cn.ibobo.lease.common.base.BaseServiceImpl;
import cn.ibobo.lease.common.dto.LeaseResDetailDTO;
import cn.ibobo.lease.common.util.UuidUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * 租赁物品详情表业务处理接口
 * @Author lililiang
 * @Date 2018-12-23 10:10:30
 */
@Service
public class LeaseResDetailServiceImpl extends BaseServiceImpl<LeaseResDetailDTO, String> implements LeaseResDetailService {

    private static final Log LOGGER = LogFactory.getLog(LeaseResDetailServiceImpl.class);

    @Autowired
    private LeaseResDetailMapper mapper;
    @Autowired
    private ResLeaseMapper resLeaseMapper;

    @Override
    protected BaseMapper<LeaseResDetailDTO, String> getMapper() {
        return mapper;
    }

    /**
     * 租赁物品详情表列表
     * @Author lililiang
     * @Date 2018-12-23 10:10:30
     * @Param
     * @Return
     */
    @Override
    public List<LeaseResDetailDTO> list4Page(LeaseResDetailDTO entity, Integer pageNum, Integer... pageSize) {
        List<LeaseResDetailDTO> leaseResDetailDTOS = super.list4Page(entity, pageNum, pageSize);
        if(leaseResDetailDTOS != null && leaseResDetailDTOS.size() >0){
            for(LeaseResDetailDTO tempDTO : leaseResDetailDTOS){
                tempDTO.setAppraiseList(resLeaseMapper.queryAppraiseByDID(tempDTO.getDid()));
            }
        }
        return leaseResDetailDTOS;
    }

    /**
     * 租赁物品详情表列表（无分页）
     * @Author lililiang
     * @Date 2018-12-23 10:10:30
     * @Param
     * @Return
     */
    @Override
    public List<LeaseResDetailDTO> listByCondition(LeaseResDetailDTO entity) {
        return super.listByCondition(entity);
    }

    /**
     * 查询租赁物品详情表详情信息
     * @Author lililiang
     * @Date 2018-12-23 10:10:30
     * @Param
     * @Return
     */
    @Override
    public LeaseResDetailDTO queryOneByPk(String id) {
        return super.queryOneByPk(id);
    }

    /**
     * 保存租赁物品详情表信息
     * @Author lililiang
     * @Date 2018-12-23 10:10:30
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer save(LeaseResDetailDTO entity) {
        String did = entity.getDid();
        if(did == null){
            entity.setDid(UuidUtil.getUuid());
            if(entity.getCode() == null){
                entity.setCode(UuidUtil.getUuid());
            }
            return mapper.add(entity);
        }else {
            return mapper.edit(entity);
        }
    }

    /**
     * 删除租赁物品详情表信息
     * @Author lililiang
     * @Date 2018-12-23 10:10:30
     * @Param
     * @Return
     */
    @Override
    @Transactional
    public Integer delete(String id) {
        return super.delete(id);
    }
}
